package cn.hh.basic.service.impl;

import cn.hh.basic.mapper.BasicMapper;
import cn.hh.basic.query.BasicQuery;
import cn.hh.basic.service.IBasicService;
import cn.hh.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BasicServiceImpl<T> implements IBasicService<T> {
    @Autowired
    private BasicMapper<T> basicMapper;


    @Override
    public List<T> loadAll() {
        return basicMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return basicMapper.loadById(id);
    }

    @Override
    public void deleteById(Long id) {
        basicMapper.deleteById(id);
    }

    @Override
    public void deleteByIds(Long[] ids) {
        basicMapper.deleteByIds(ids);
    }

    @Override
    public void update(T t) {
        basicMapper.update(t);
    }

    @Override
    public void add(T t) {
        basicMapper.add(t);
    }

    @Override
    public PageList<T> queryPage(BasicQuery query) {
        Integer total=basicMapper.queryCount(query);
        List<T> bags = basicMapper.queryData(query);
        PageList<T> pageList = new PageList<>(total, bags);
        return pageList;
    }

}
